package com.yun.util.clickHouse;


import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.sql.DataSource;

@Configuration
public class DataConfiguration implements WebMvcConfigurer {
	
//	@Value("${spring.datasource.clickhouse.driverClass}")
//	private String driverClassName;
//
//    @Value("${spring.datasource.clickhouse.jdbcUrl}")
//    private String jdbcUrl;
//
//    @Value("${spring.datasource.clickhouse.user}")
//    private String username;
//
//    @Value("${spring.datasource.clickhouse.password}")
//    private String password;
	
    @Bean(name = "dataSource")
    @Qualifier(value = "dataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.mysql")
    public DataSource dataSource(){
    	DataSource dataSource = DataSourceBuilder.create()
    			.type(ComboPooledDataSource.class).build();
    	return dataSource;
    }
	 
//    @RefreshScope
    @Bean(name = "clickhouseDataSource")
    @Qualifier(value = "clickhouseDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.clickhouse")
    public DataSource clickhouse(){
    	DataSource dataSource = DataSourceBuilder.create()
    			.type(ComboPooledDataSource.class).build();
		return dataSource;
    }
	 
}
